package com.halflife.nio;


import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.ServerSocket;
import java.net.Socket;

public class SocketIO {
    //sadasdadsf
    public static void main(String[] args) throws Exception{
        ServerSocket server = new ServerSocket(9090);
        System.out.println("step1: new ServerSocket"+server.toString());
        Socket client = server.accept();// blocking
        System.out.println("step2: accept client;" + client);
        InputStream in = client.getInputStream();
        BufferedReader reader = new BufferedReader(new InputStreamReader(in));
        String abc = "";
        int count = 0;
        int limit = 0;
        while (true) {
            if ((abc = reader.readLine()) !=null) {//blocking
                System.out.println(abc);
//            client.getOutputStream().write("ok".getBytes());
//            limit++;
//            if (limit > 5) {
//                client.getOutputStream().write("guanbi".getBytes());
//                client.getOutputStream().close();
//                reader.close();
//                client.close();
//                break;
//            }
            }
        }


    }
}
